define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'test/test/index' + location.search,
                    add_url: 'test/test/add',
                    edit_url: 'test/test/edit',
                    del_url: 'test/test/del',
                    multi_url: 'test/test/multi',
                    import_url: 'test/test/import',
                    table: 'test',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'article.title', title: "对应文章"},
                        {field: 'merchant.abbr', title: "出题企业"},
                        {field: 'title', title: __('Title'), operate: 'LIKE'},
                       
                        {field: 'number', title: __('Number'), operate: 'LIKE'},
                        {field: 'total_score', title: __('Total_score')},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
                        // {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'limittime', title:"限时(分)"},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        {
                            field: 'buttons', title:"显示", table: table,
                            buttons: [
                                {
                                    name: 'testitem',
                                    text: __('试题列表'),
                                    classname: 'btn btn-xs btn-success btn-dialog',
                                    icon: 'fa fa-tasks',
                                    url: 'test/testitem/index/test_id/{ids}'
                                },
                                {
                                    name: 'chooseitem',
                                    text: __('试题选择'),
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    icon: 'fa fa-hand-stop-o',
                                    url: 'test/testitem/chooseitem/test_id/{ids}'
                                }
                            ],
                            formatter: Table.api.formatter.buttons
                        },
                        {
                            field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
							buttons:
							[	
								{
									name:"preview_test_item",
									text:"预览",
									title:__("预览试卷"),
									classname:"btn btn-xs btn-primary btn-dialog",
									icon:"fa fa-eye",
									url:"test/test/preview",
									callback:function(data){
										console.log(data);
									}		
								}
							],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});